﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using ChanExt;
using C.Unite;
using C.Entities;

namespace ArtLand.OA.Project.ADM
{
    public partial class Adm_ExpnseChange : CommonPageBase
    {
        public string ContentS = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataBaseHelper.BindDrp(Drp_MoneyType, EnumData.DataBaseEunm.MoneyTypet);
                FormInfo.ShowTriggerWin(Window1, txt_USRNAM, hid_USRNAM, "/PublicModel/SelectUsers.aspx?single=1", "选择申请人");
                FormInfo.ShowTriggerWin(Window1, txt_Auditer, hid_AuditUID, "/PublicModel/SelectUsers.aspx?single=1", "选择审批人");
                btnClose.OnClientClick = ActiveWindow.GetHideReference();
                LoadData();
            }
        }

        protected void LoadData()
        {
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                Adm_EXPNSE Exp = TbsDbSession.Default.From<Adm_EXPNSE>().Where(Adm_EXPNSE._.ID == int.Parse(Request["id"])).ToFirst();
                if (Exp != null)
                {
                    txt_USRNAM.Text = Exp.USRNAM;
                    txt_REMARK.Text = Exp.REMARK;
                    txt_PLDATE.Text = Exp.PLDATE.Value.ToString("yyyy-MM-dd");
                    txt_APDATE.Text = Exp.APDATE.Value.ToString("yyyy-MM-dd");
                    txt_AMOUNT.Text = Exp.AMOUNT.Value.ToString();
                    CHK_STATUS.Checked = Exp.CHKBUG.Value;
                    txt_Auditer.Text = Exp.Auditer;
                    hid_AuditUID.Text = Exp.AuditEmpNO;
                    Drp_MoneyType.SelectedValue = Exp.MoneyType;
                }
                if (!string.IsNullOrEmpty(Request["s"]))
                {
                    tool1.Hidden = false;
                    tool2.Hidden = true;
                    txt_USRNAM.Readonly = true;
                    txt_REMARK.Readonly = true;
                    txt_PLDATE.Readonly = true;
                    txt_APDATE.Readonly = true;
                    CHK_STATUS.Enabled = false;
                    txt_Auditer.Enabled = false;

                }
                else
                {
                    tool1.Hidden = true;
                    tool2.Hidden = false;
                }
            }
            else
            {
                tool1.Hidden = true;
                tool2.Hidden = false;
            }
        }


        protected void btnSave_Click(object sender, EventArgs e)
        {
            int returnvalue = 0;
            Adm_EXPNSE Exp = new Adm_EXPNSE();
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                Exp.ID = int.Parse(Request["id"]);
                Exp.Attach();
                Exp.AMOUNT = Convert.ToDecimal(txt_AMOUNT.Text);
                Exp.APDATE = Convert.ToDateTime(txt_APDATE.Text);
                Exp.CHKBUG = CHK_STATUS.Checked;
                Exp.USRNAM = txt_USRNAM.Text;
                Exp.REMARK = txt_REMARK.Text;
                Exp.Auditer = txt_Auditer.Text;
                Exp.AuditEmpNO = hid_AuditUID.Text;
                Exp.PLDATE = Convert.ToDateTime(txt_PLDATE.Text);
                Exp.MoneyType = Drp_MoneyType.SelectedValue;
                returnvalue = TbsDbSession.Default.Update<Adm_EXPNSE>(Exp);
            }
            else
            {
                Exp.DeAttach();
                Exp.AMOUNT = Convert.ToDecimal(txt_AMOUNT.Text);
                Exp.APDATE = Convert.ToDateTime(txt_APDATE.Text);
                Exp.CHKBUG = CHK_STATUS.Checked;
                Exp.SUBTYP = int.Parse(Request["cid"]);
                Exp.USRNAM = txt_USRNAM.Text;
                Exp.STATUS = 0;
                Exp.REMARK = txt_REMARK.Text;
                Exp.PLDATE = Convert.ToDateTime(txt_PLDATE.Text);
                Exp.Auditer = txt_Auditer.Text;
                Exp.AuditEmpNO =hid_AuditUID.Text;
                Exp.Adder = CookInfo.EAdminTrueName();
                Exp.AddTime = DateTime.Now;
                Exp.Adduid = CookInfo.EAdminid();
                Exp.MoneyType = Drp_MoneyType.SelectedValue;
                returnvalue = TbsDbSession.Default.Insert<Adm_EXPNSE>(Exp);
            }
            if (returnvalue > 0)
            {
                Alert.Show("更新成功！", "提示", ActiveWindow.GetHideRefreshReference());
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            int id = int.Parse(Request["id"]);
            Adm_EXPNSE vc = new Adm_EXPNSE();
            vc.ID = id;
            vc.Attach();
            vc.STATUS = 1;
            TbsDbSession.Default.Update<Adm_EXPNSE>(vc);

            Alert.Show("审批结束", "提示", ActiveWindow.GetHideRefreshReference());
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            int id = int.Parse(Request["id"]);
            Adm_EXPNSE vc = new Adm_EXPNSE();
            vc.ID = id;
            vc.Attach();
            vc.STATUS = 2;
            TbsDbSession.Default.Update<Adm_EXPNSE>(vc);
            Alert.Show("审批结束", "提示", ActiveWindow.GetHideRefreshReference());
        }
    }
}